<?php
namespace jy_weishopke;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	/*
	   购买会员
	*/
	public function upmsg($msgtype,$uid='',$o_id='',$order_id=''){
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
		$adminuid = $this->plugin_setting('basic')['adminuid'];
		if($msgtype == 'buyvip'){
			$url=custom_url('jy_weishopke/member.index/',true);
			$tpldata=array(
				'first'=>array('value'=>'您好，有一条购买VIP消息！','color'=>''),
				'remark'=>array('value'=>$member['nickname'].'-刚刚购买了VIP，点击查看VIP购买记录~!','color'=>'#ff510'),
			);
			$url2=custom_url('jy_weishopke/member.index/viplog/',true);
			$newsmsg['msgtype']='news';
			$articles[0]['title'] = "您好，有一条购买VIP消息！\n";
			$articles[0]['description']=$member['nickname'].'-刚刚购买了VIP，点击查看VIP购买记录~!';
			$articles[0]['url'] =$url2;
			$articles[0]['picurl']=$member['avatar'];
			$newsmsg['news']['articles'] =$articles;
			$this->send_message('getvip',$newsmsg,$tpldata,$adminuid,$url2,$color);
			
		}
	}
	/*
	  发送消息
	*/
	public function send_message($msgtype,$newsmsg,$tpldata,$uid='',$url2='',$color=''){
		$tpl=$this->plugin_setting('basic');
		if($msgtype=='setred'){
			if($tpl['setred'] && $tpl['istpl']){
				cfc('account')->sendTplNotice($uid,$tpl['setred'],$tpldata,$url,$color);
				return true;
			}else{
				cfc('account')->sendCustomNotice($newsmsg,$uid);
				return true;
			}
		}elseif($msgtype=='getred'){
			if($tpl['getred'] && $tpl['istpl']){
				cfc('account')->sendTplNotice($uid,$tpl['getred'],$tpldata,$url,$color);
				return true;		
			}else{
				cfc('account')->sendCustomNotice($newsmsg,$uid);
				return true;
			}
			
		}elseif($msgtype=='buyvip'){
			if($tpl['buyvip'] && $tpl['istpl']){
				cfc('account')->sendTplNotice($uid,$tpl['buyvip'],$tpldata,$url,$color);	
				return true;
			}else{
				cfc('account')->sendCustomNotice($newsmsg,$uid);
				return true;
			}
			
		}elseif($msgtype=='getvip'){
			if($tpl['getvip'] && $tpl['istpl']){
				cfc('account')->sendTplNotice($uid,$tpl['getvip'],$tpldata,$url,$color);
				return true;		
			}else{
				cfc('account')->sendCustomNotice($newsmsg,$uid);
				return true;
			}
	
		}
	}
}